//
//  PersonInfoViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/7/25.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

class PersonInfoViewController: BaseTableViewController {
    
    var source: Array<JSON> = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.separatorInset = .zero
        self.tableView.register(UINib.init(nibName: "PersonInfoCell", bundle: Bundle.main), forCellReuseIdentifier: "PersonInfoCell")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.source.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return tableView.dequeueReusableCell(withIdentifier: "PersonInfoCell")!
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 54
    }
    
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        let cel = cell as! PersonInfoCell
        
        cel.model = self.source[indexPath.row]
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        
        let header = UIView()
        header.backgroundColor = UIColor.dftBack
        let stack = UIStackView.init()
        header.addSubview(stack)
        stack.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalToSuperview().offset(-1)
        }
        let line = UIView()
        line.backgroundColor = UIColor.hex("eeeeee")
        header.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(1)
            make.bottom.equalToSuperview()
        }
        stack.axis = .horizontal
        stack.alignment = .fill
        stack.spacing = 1
        stack.distribution = .fillEqually
        let nameLabel = UILabel()
        nameLabel.text = "工号"
        nameLabel.backgroundColor = .white
        nameLabel.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
        nameLabel.textAlignment = .center
        stack.addArrangedSubview(nameLabel)
        let predicateLabel = UILabel()
        
        predicateLabel.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
        
        predicateLabel.backgroundColor = .white
        
        predicateLabel.text = "姓名"
        
        predicateLabel.textAlignment = .center
        
        stack.addArrangedSubview(predicateLabel)
        
        let remarkLabel = UILabel()
        
        remarkLabel.backgroundColor = .white
        
        remarkLabel.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
        
        remarkLabel.text = "岗位"
        
        remarkLabel.textAlignment = .center
        
        stack.addArrangedSubview(remarkLabel)
        
        let typeLabel = UILabel()
        
        typeLabel.text = "用工类型"
        
        typeLabel.backgroundColor = .white
        
        typeLabel.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.bold)
        
        typeLabel.textAlignment = .center
        
        stack.addArrangedSubview(typeLabel)
        
        return header
    }

}
